<?php
namespace Home\Controller;
use Think\Controller;
class LaborController extends Controller{
    public function index(){
        $this->display();
    }
   //获取村
    public function getVillage($pid){
        $village = M('Areas') -> where('pid = '.$pid) -> field('area_name,id') ->select();
        //print_r($village);
        $this -> ajaxReturn($village);
    }
    // lhx
    public function laborAdd(){
    	$tianbiao=time();//填表时间



    	





    	$this->assign("tianbiao",$tianbiao);
        $this->display();
    }
    //实现添加功能 lhx
    public function laddo(){
    	$mod=M("user_farmer");
    	// $mod->create();
    	$data=$_POST;
    	$data['uf_time']=time();
    	$dd=$mod->add($data);
    	if($dd){
            $arr ['status'] = 100;
            $arr ['info'] = "添加成功!";
            $arr ['name']=$_POST['uf_name'];
            $arr ['uf_card']=$_POST['uf_card'];
            $this->ajaxReturn ( $arr );
        }else{
            $arr ['status'] = 101;
            $arr ['info'] = "添加失败!";
            $this->ajaxReturn ( $arr );
        }
    } 

    // 录入信息
    public function laborAddData(){
        $status =I("status");

        $name=I("name");
        $uf_card =I("uf_card");


        if($status){
            $this->assign("status",$status);
        }


    
            // dump($_POST);
        $this->assign("name",$name);
        $this->assign("uf_card",$uf_card);
        $this->display();
    }
    //录入信息动作
    public function laborAddDatado(){

        if ($_POST['l_name'] != null || $_POST['l_card'] != null) {
            $f = M("user_farmer");
            $find = $f->where("uf_name = '{$_POST['l_name']}' AND uf_card = '{$_POST['l_card']}'")->find();
            if($find){
                 $list=$_POST;
                    foreach($list as $k=>$v){
                        $data=explode("_", $k);
                                if($data[0]=="ls"){ 
                           // $data_one['ls_uf_id']=$find['uf_id'];
                           $data_one[$k]=$v;//劳动技能
                        }else if ($data[0] == "we") {
                           $data_two[$k]=$v;//从业经历
                        }else if ($data[0] == "te") {
                           $data_three[$k]=$v;//培训经历
                        }else if ($data[0] == "cw") {
                           $data_four[$k]=$v;//当前务工情况
                        }else if ($data[0] == "ei") {
                           $data_five[$k]=$v;//就业意向
                        }else if ($data[0] == "et") {
                           $data_six[$k]=$v;//当前务工情况
                        }

                    }
                    if ($data_one  && $data_five  && $data_six) {
                    $mod=M("labor_skill");
                    $mod2=M("working_experience");
                    $mod3=M("training_experience");
                    $mod4=M("current_workers");
                    $mod5=M("employment_intention");
                    $mod6=M("employment_time");
                    $data_one['ls_uf_id']=$find['uf_id'];
                    $data_two['we_uf_id']=$find['uf_id'];
                    $data_three['te_uf_id']=$find['uf_id'];
                    $data_four['cw_uf_id']=$find['uf_id'];
                    $data_five['ei_uf_id']=$find['uf_id'];
                    $data_six['et_uf_id']=$find['uf_id'];
                    $re1=$mod->add($data_one);
                    $re2=$mod2->add($data_two);
                    $re3=$mod3->add($data_three);
                    $re4=$mod4->add($data_four);
                    $re5=$mod5->add($data_five);
                    $re6=$mod6->add($data_six);
                    if($re1  && $re5  && $re6){
                        $success = 1;
                        $this->redirect('Labor/laborAddData',array('status'=>100));
                        // $this->laborAddData($success);
                        // $this->success("添加成功!");
                    }else{
                        $this->error("添加失败,请将信息补全!");
                    }
                       

                      
                    }else{
                        $this->error("添加失败,请将信息补全!"); 
                    }

            }else{
                $this->error("未查到该用户!");
            }
        }else{
            $this->error("请填写用户信息!");
        }
   
    }





}